<template>
    <v-snackbar :timeout="timeout" right top :color="color" v-model="active" auto-height multi-line v-if="!destroy">
        {{message}}
        <v-btn dark icon @click="active = false">
            <v-icon>mdi-close</v-icon>
        </v-btn>
    </v-snackbar>
</template>

<script>
    export default {
        name: "Toast",
        data() {
            return {
                timeout: 3000,
                message: '',
                color: 'info',
                active: false,
                destroy: false,
            }
        },
        methods: {
            show(message, color) {
                this.message = message;
                this.color = color;
                this.active = true;
            },
            close () {
                this.active = false;
            }
        },
        watch: {
            async active (n) {
                if (n === false) {
                    await this.$nextTick();
                    this.destroy = true;
                    this.$destroy();
                }
            }
        }
    }
</script>

<style scoped>

</style>